
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>后台登录</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/admin/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/admin/bower_components/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/admin/bower_components/Ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="/admin/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="/admin/plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href="/">瓯讯网络</a>
    </div>
    <div class="login-box-body" style="padding:50px 30px;">
        <p class="login-box-msg">请使用员工账号</p>
        <form action="" method="post">
            <div class="form-group has-feedback">
                <input type="text" class="form-control" name="username" placeholder="账号" />
                <span class="glyphicon glyphicon-user form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" name="password" placeholder="密码" />
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8"></div>
                <div class="col-xs-4">
                    <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 脚本 -->
<script src="/admin/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/admin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/admin/plugins/layer/layer.js"></script>
<script>
$(function () {
    $("form").bind("submit", function(){
        var username = $('input[name=username]').val();
        if(username == ""){
            $('input[name=username]').focus();
            return false;
        }
        var password = $('input[name=password]').val();
        if(password == ""){
            $('input[name=password]').focus();
            return false;
        }

        var url = "{:config('api_url')}";
        jQuery.post(url+'/rbac/checkStaff',{'username':username,password:password},function(res){
            if(res.code==200){
                var token = res.data.token;
                if(!token){
                    layer.alert('帐号或密码错误');
                    return;
                }
                localStorage.setItem('sup_staff_token',token);

                jQuery.post('/admin/index/saveLogin',{'sup_staff_token':token},function(res){
                    if(res.code==200){
                        if(document.referrer == "" || document.referrer == location.href){
                            location.href= "/admin/index/index";
                        }else{
                            location.href = document.referrer;
                        }
                    }else{
                        layer.alert('系统忙');
                    }
                });
            }else{
                layer.alert('系统忙');
            }
        });


        return false;
    });
});
</script>
</body>
</html>
